package pattern5.ProducerConsumer.demo1.client;

import pattern5.ProducerConsumer.demo1.msgServer.Producer;
import pattern5.ProducerConsumer.demo1.msgServer.Msg;
import pattern5.ProducerConsumer.demo1.msgServer.MsgManager;

/**
 * @创建人 liweijia
 * @创建时间 2022/7/29
 * @描述 程序的主要用途
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        // 新建一个消息队列组件
        MsgManager msgManager = new MsgManager(10);

        // 新建消费者,并运行
        MyConsumer myConsumer = new MyConsumer(msgManager);
        myConsumer.start();

        // 生产者每一段时间生成一个消息
        MyProducer producer = new MyProducer(msgManager);
        int msgIndex = 1;
        while (true) {
            Thread.sleep(1000);
            producer.send(new Msg().setMsg(String.valueOf(msgIndex)));
            msgIndex++;
        }

    }
}
